﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using oLGame.Game;
using oLGame.Game.Items.Weapons;
namespace oLGame.Game.Players
{
    class PlayerAttackAction : BaseSystemAction
    {
        protected int damageMin, damageMax;
        protected Player playerFrom, playerTo;
        public PlayerAttackAction(Player from, Player to)
        {
            playerFrom = from;
            playerTo = to;

            // If the player has no item equiped then set his weapon to a new instance of Fists.
            if (from.Weapon == null)
                from.Weapon = new Fists();

            damageMin = from.Weapon.MinimumDamage;
            damageMax = from.Weapon.MaximumDamage;
        }

        public override bool Invoke()
        {
            //OnAttacked(EventArgs.Empty);
            Random random = new Random();
            int damageDealt = random.Next(damageMin-1,damageMax)+1;
            OnLog(playerFrom.Name + "(#" + playerFrom.EntityID + ") attacks " + playerTo.Name + "(#" + playerTo.EntityID + ") using " + playerFrom.Weapon.Name + "(#" + playerFrom.Weapon.EntityID + ") dealing " + damageDealt + " damage.");
            if (!playerFrom.IsDead())
            {
                playerTo.TakeDamage(damageDealt);
                return true;
            }
            return false;
        }
    }
}
